home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2001 May / maximum-cd-2001-05.iso / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / NetScorer.py < prev    next >
Encoding:
Python Source  |  2000-11-16  |  13.4 KB  |  385 lines

  1. import netgame
  2. import BUIx
  3. import CharStats
  4. import Netval
  5. import Bladex
  6. import ScorerWidgets
  7. import WidgetsExtra
  8. import MenuText
  9. from Reference import ENERGY_LOW_LEVEL
  10.  
  11. wants_auto_scale = 1
  12.  
  13. VISIBLE=1
  14.  
  15. CURRENT_STRENGTH_R=251
  16. CURRENT_STRENGTH_G=241
  17. CURRENT_STRENGTH_B=2
  18.  
  19.  
  20. __wNULL=BUIx.CreateNULLWidget()
  21. wFrame=BUIx.B_FrameWidget(__wNULL,"MainFrame",640,480)
  22.  
  23. # life and level
  24. wLeftFrame=BUIx.B_FrameWidget(wFrame,"BarsFrame",195,65)
  25.  
  26. wDownFrame=BUIx.B_FrameWidget(wFrame,"DownFrame",195,73)
  27. wChatFrame=BUIx.B_FrameWidget(wFrame,"ChatFrame",195,65)
  28.  
  29. wFragFrame=BUIx.B_FrameWidget(wFrame,"FragFrame",200,200)
  30.  
  31.  
  32. Bladex.ReadBitMap("..\\..\\Data\\Bar.bmp","BitmapBarra")
  33. Bladex.ReadBitMap("../../Data/Vida.bmp","Vida")
  34.  
  35. wLifeMarker = BUIx.B_BitmapWidget(wLeftFrame,"ObjNameBg",205,51,"MARCADORVIDARED","../../Data/marcadorvidared.mmp");
  36. wLifeMarker.SetColor(255,255,255)
  37. wLifeMarker.SetAlpha(1.0)
  38.  
  39. BAR_DELTA = 26
  40.  
  41. wLifeBar=WidgetsExtra.B_FlashBarWidget(wLeftFrame,"LifeBar",116+BAR_DELTA,10)
  42. wLifeBar.SetColor(255,0,0)
  43. wLifeBar.SetFlashColor(53, 141, 36)
  44. wLifeBar.SetFlash(0)
  45. wLifeBar.Continuous= 1
  46. wLifeBar.SetBackgroundAlpha(0.0)
  47. wLifeBar.SetAlpha(1.0)
  48. wLifeBar.SetBitmap("Vida")
  49.     
  50.  
  51. ##def wLifeBarSizeChanged(x,y):
  52. ##  print "wLifeBarSizeChanged",x,y
  53. ##  
  54. ##wLifeBar.SetSizeChangedFunc(wLifeBarSizeChanged)
  55.  
  56. wLifeLabel=BUIx.B_TextWidget(wLifeBar,"LifeLabel","100/100",ScorerWidgets.font_server,"../../Data/Mapa de letras.bmp")
  57. wLifeLabel.SetColor(255,0,0)
  58. wLifeLabel.SetAlpha(1.0)
  59. wLifeBar.AddLabel(wLifeLabel,4-BAR_DELTA,-2,
  60.                   BUIx.B_Widget.B_LAB_Right,BUIx.B_Widget.B_LAB_VCenter,
  61.                   BUIx.B_Widget.B_FR_AbsoluteLeft,BUIx.B_Widget.B_FR_Left,
  62.                   BUIx.B_Widget.B_FR_AbsoluteTop,BUIx.B_Widget.B_FR_Top
  63.                   )
  64.  
  65.  
  66. wPoisonLabel=BUIx.B_TextWidget(wLifeBar,"PoisonLabel",MenuText.GetMenuText("POISONED"),ScorerWidgets.font_server,"../../Data/Mapa de letras.bmp")
  67. wPoisonLabel.SetColor(85,105,60)
  68. wPoisonLabel.SetAlpha(1.0)
  69. wLifeBar.AddLabel(wPoisonLabel,0.4,0.5,
  70.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_VCenter,
  71.                   BUIx.B_Widget.B_FR_HRelative, BUIx.B_Widget.B_FR_HCenter,
  72.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  73.                   )
  74. wPoisonLabel.SetVisible(0)
  75.                   
  76.  
  77. wCurrentLevelLabel=BUIx.B_TextWidget(wLifeBar,"CurrentLevelLabel","Level 5",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  78. wCurrentLevelLabel.SetColor(0,159,220)
  79. wCurrentLevelLabel.SetAlpha(0.5)
  80. wLifeBar.AddLabel(wCurrentLevelLabel,0,5,
  81.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_Bottom,
  82.                   BUIx.B_Widget.B_FR_AbsoluteLeft,BUIx.B_Widget.B_FR_Left,
  83.                   BUIx.B_Widget.B_FR_AbsoluteTop,BUIx.B_Widget.B_FR_Top
  84.                   )
  85.  
  86. # Frags
  87. wPlayersFrags=BUIx.B_TextWidget(wLifeBar,"FragsLabel","",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  88. wPlayersFrags.SetColor(220,220,220)
  89. wPlayersFrags.SetAlpha(0.8)
  90. wLifeBar.AddLabel(wPlayersFrags,0,5,
  91.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_Bottom,
  92.                   BUIx.B_Widget.B_FR_AbsoluteLeft,BUIx.B_Widget.B_FR_Left,
  93.                   BUIx.B_Widget.B_FR_AbsoluteTop,BUIx.B_Widget.B_FR_Top
  94.                   )
  95.  
  96.  
  97. # versus value
  98. wPlayersVS=BUIx.B_TextWidget(wLifeBar,"VersusLabel","Waiting for a combat...",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  99. wPlayersVS.SetColor(220,220,220)
  100. wPlayersVS.SetAlpha(0.7)
  101. wDownFrame.AddWidget(wPlayersVS,0,0)
  102.  
  103. # Status of the client
  104. wStatusGame=BUIx.B_TextWidget(wLifeBar,"VersusLabel","",ScorerWidgets.font_server,"..\\..\\Data\\letras menu peq.BMP")
  105. wStatusGame.SetColor(0,128,255)
  106. wStatusGame.SetAlpha(0.8)
  107. wDownFrame.AddWidget(wStatusGame,0,16)
  108.  
  109.  
  110. # Barra de un bar    -------------------------------------------------------------------------------------------
  111. wLowBarFrame=BUIx.B_FrameWidget(wFrame,"LowBarFrame",176, 22)
  112. wLowBarFrame.SetVisible(1)
  113.  
  114.  
  115. wEnergyBmp=BUIx.B_BitmapWidget(wLowBarFrame,"EnergyBmp",176, 22,"MARCADORLANZAMAGOTAM","../../Data/marcadorlanzamagotam.mmp")
  116. wEnergyBmp.SetColor(255,255,255)
  117. wEnergyBmp.SetAlpha(1.0)
  118. wEnergyBmp.SetVisible(1)
  119.  
  120. # Barra de strength  -------------------------------------------------------------------------------------------
  121. wStrengthBar=ScorerWidgets.B_SmoothBarWidget(wLowBarFrame,"StrengthBar",112*(8.0/6.5),8)
  122. wStrengthBar.SetColor(CURRENT_STRENGTH_R,CURRENT_STRENGTH_G,CURRENT_STRENGTH_B)
  123. wStrengthBar.SetAlpha(0.75)
  124. wStrengthBar.SetBackgroundAlpha(0.0)
  125. wStrengthBar.SetBackgroundColor(CURRENT_STRENGTH_R,CURRENT_STRENGTH_G,CURRENT_STRENGTH_B)
  126. wStrengthBar.SetVisible(0)
  127. wStrengthBar.SetBitmap("Vida")
  128.  
  129. wMaxPowerLabel=WidgetsExtra.B_FlashTextWidget(wStrengthBar,"MaxPowerLabel",MenuText.GetMenuText("Maximun power"),ScorerWidgets.font_server,"../../Data/Mapa de letras.bmp")
  130. wMaxPowerLabel.SetColor(255,255,255)
  131. wMaxPowerLabel.SetAlpha(1.0)
  132. wMaxPowerLabel.SetVisible(0)
  133. wStrengthBar.AddLabel(wMaxPowerLabel,0.4,0.5,
  134.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_VCenter,
  135.                   BUIx.B_Widget.B_FR_HRelative, BUIx.B_Widget.B_FR_HCenter,
  136.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  137.                   )
  138.  
  139. wStrengthLabel=WidgetsExtra.B_FlashTextWidget(wStrengthBar,"StrengthLabel",MenuText.GetMenuText("Launch"),ScorerWidgets.font_server,"../../Data/Mapa de letras.bmp")
  140. wStrengthLabel.SetColor(251,210,99)
  141. wStrengthLabel.SetAlpha(1.0)
  142. wStrengthLabel.SetFlash(0.0)
  143. wStrengthBar.AddLabel(wStrengthLabel,9,0.5,
  144.                   BUIx.B_Widget.B_LAB_Left,BUIx.B_Widget.B_LAB_VCenter,
  145.                   BUIx.B_Widget.B_FR_AbsoluteRight,BUIx.B_Widget.B_FR_Right,
  146.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  147.                   )
  148.  
  149. #wStrengthBar.SetBitmap("BitmapBarra")
  150.  
  151. # Barra de energy  -------------------------------------------------------------------------------------------
  152. wEnergyBar=ScorerWidgets.B_SmoothBarWidget(wLowBarFrame,"EnergyBar",112*(8.0/6.5),8)
  153. wEnergyBar.SetColor(0,255,128)
  154. wEnergyBar.SetAlpha(0.75)
  155. wEnergyBar.SetBackgroundAlpha(0.0)
  156. wEnergyBar.SetBackgroundColor(64,64,64)
  157. wEnergyBar.SetVisible(0)
  158. wEnergyBar.SetBitmap("Vida")
  159.  
  160. wDangerLabel=WidgetsExtra.B_FlashTextWidget(wEnergyBar,"DangerLabel",MenuText.GetMenuText("Low energy"),ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  161. wDangerLabel.SetColor(238,191,0)
  162. wDangerLabel.SetAlpha(1.0)
  163. wDangerLabel.SetVisible(0)
  164. wEnergyBar.AddLabel(wDangerLabel,0.4,0.5,
  165.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_VCenter,
  166.                   BUIx.B_Widget.B_FR_HRelative, BUIx.B_Widget.B_FR_HCenter,
  167.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  168.                   )
  169.  
  170. wEnergyMaxLabel=WidgetsExtra.B_FlashTextWidget(wEnergyBar,"EnergyMaxLabel","100",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  171. wEnergyMaxLabel.SetColor(0,255,128)
  172. wEnergyMaxLabel.SetAlpha(1)
  173. wEnergyMaxLabel.SetVisible(1)
  174. wEnergyBar.AddLabel(wEnergyMaxLabel,7,0.5,
  175.                   BUIx.B_Widget.B_LAB_Left,BUIx.B_Widget.B_LAB_VCenter,
  176.                   BUIx.B_Widget.B_FR_AbsoluteRight, BUIx.B_Widget.B_FR_Right,
  177.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  178.                   )
  179.  
  180.  
  181. wLowBarFrame.AddWidget(wStrengthBar,56,6)
  182.  
  183. wLowBarFrame.AddWidget(wEnergyBar,56,6)
  184.  
  185. wLowBarFrame.AddWidget(wEnergyBmp,0,0)
  186.                   
  187. wChatLines = ["","","",""]
  188.  
  189. for i in range(len(wChatLines)):
  190.     wChatLines[i]=BUIx.B_TextWidget(wLifeBar,"VersusLabel","",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  191.     wChatLines[i].SetColor(220,220,220)
  192.     wChatLines[i].SetAlpha((i+1.0)/(len(wChatLines)))
  193.     wChatFrame.AddWidget(wChatLines[i],0,i*14)
  194.  
  195. # FragLimit
  196. wFragLimit=BUIx.B_TextWidget(wLifeBar,"FragLimimit",MenuText.GetMenuText("THE CARNAGE IS OVER"),ScorerWidgets.font_server,"..\\..\\Data\\letras menu med.BMP")
  197. wFragLimit.SetColor(255,0,0)
  198. wFragLimit.SetAlpha(0.8)
  199. wFragFrame.AddWidget(wFragLimit,0,5)
  200.  
  201. wFragList=BUIx.B_TextWidget(wLifeBar,"FragLimimit","",ScorerWidgets.font_server,"..\\..\\Data\\letras menu med.BMP")
  202. wFragList.SetColor(220,220,220)
  203. wFragList.SetAlpha(0.8)
  204. wFragFrame.AddWidget(wFragList,0,25)
  205.  
  206.  
  207. ##############################################################################################
  208. wFrame.SetVisible(1)
  209. wLeftFrame.SetVisible(1)
  210. wDownFrame.SetVisible(1)
  211. wFragFrame.SetVisible(0)
  212.  
  213. # muestra la lista grande de frags
  214. def ShowFragLimit(val):
  215.     wLeftFrame.SetVisible(val)
  216.     wDownFrame.SetVisible(val)
  217.     wChatFrame.SetVisible(val)
  218.     wLowBarFrame.SetVisible(val)
  219.     wFragFrame.SetVisible(val==0)
  220.  
  221.  
  222. wFrame.AddWidget(wLeftFrame,0,0)
  223.  
  224. wLeftFrame.AddWidget(wLifeBar,14,6)
  225. wLeftFrame.AddWidget(wLifeMarker,1,1)
  226.  
  227. wFrame.AddWidget(wDownFrame,0.5,20,BUIx.B_FrameWidget.B_FR_HRelative,BUIx.B_FrameWidget.B_FR_HCenter,
  228.                               BUIx.B_FrameWidget.B_FR_AbsoluteBottom,BUIx.B_FrameWidget.B_FR_VCenter)
  229.  
  230. wFrame.AddWidget(wChatFrame,20,20,BUIx.B_FrameWidget.B_FR_AbsoluteRight,BUIx.B_FrameWidget.B_FR_Right,
  231.                               BUIx.B_FrameWidget.B_FR_AbsoluteTop,BUIx.B_FrameWidget.B_FR_Top)
  232.  
  233. wFrame.AddWidget(wFragFrame,0.5,0.5,BUIx.B_FrameWidget.B_FR_HRelative,BUIx.B_FrameWidget.B_FR_HCenter,
  234.                               BUIx.B_FrameWidget.B_FR_AbsoluteTop)
  235.  
  236. wFrame.AddWidget(wLowBarFrame,0.5,2,
  237.                            BUIx.B_FrameWidget.B_FR_HRelative,BUIx.B_FrameWidget.B_FR_HCenter,
  238.                            BUIx.B_FrameWidget.B_FR_AbsoluteBottom,BUIx.B_FrameWidget.B_FR_Bottom)
  239.                            
  240.  
  241. Bladex.SetRootWidget(wFrame.GetPointer())
  242.  
  243. ScrollLimit = 0
  244.  
  245. def SetStrengthBarValue(v):
  246.   wEnergyBar.SetVisible(0)  
  247.   if VISIBLE:
  248.       wStrengthBar.SetVisible(1)
  249.   old_pos= wStrengthBar.GetPositionPercentage()  
  250.   wStrengthBar.SetPositionPercentage(v*(6.5/8.0))  
  251.   
  252.   if v>=1.0:
  253.       if old_pos<1.0:
  254.           wMaxPowerLabel.SetFlash(14)
  255.           wStrengthLabel.SetFlash(14)          
  256.           wMaxPowerLabel.SetVisible(1)
  257.   else:
  258.       wMaxPowerLabel.SetVisible(0)
  259.       wStrengthLabel.SetFlash(0.0)
  260.       
  261. def SetEnergyBarValue(v, max_v):
  262.   wStrengthBar.SetVisible(0)
  263.   if VISIBLE:
  264.       wEnergyBar.SetVisible(1)
  265.   pos= min(max(v/max_v, 0),1.0)
  266.   wEnergyMaxLabel.SetText(`int(max_v)`)
  267.   wEnergyBar.SetPositionPercentage(pos*(6.5/8.0))
  268.   wEnergyBar.RecalcLabelLayout(BUIx.B_Widget.B_LAB_Left,BUIx.B_Widget.B_LAB_VCenter)
  269.   if pos<=ENERGY_LOW_LEVEL:            
  270.       wDangerLabel.SetFlash(14)      
  271.       wDangerLabel.SetVisible(1)
  272.   else:
  273.       wDangerLabel.SetVisible(0)  
  274.  
  275. def ScrollChatConsole():
  276.     global ScrollLimit
  277.     for i in range(len(wChatLines)-1):
  278.         wChatLines[i].SetText(wChatLines[i+1].GetTextData())
  279.     wChatLines[len(wChatLines)-1].SetText("")
  280.     ScrollLimit = Bladex.GetTime()+3.0
  281.     
  282.  
  283. def ChatClientString(cad):
  284.     ScrollChatConsole()
  285.     wChatLines[len(wChatLines)-1].SetText(cad)
  286.     
  287.     
  288. def AddChatString(cad):
  289.     if netgame.GetNetState() != 2:
  290.         ScrollChatConsole()
  291.         wChatLines[len(wChatLines)-1].SetText(cad)
  292.     netgame.SendUserString(Netval.NET_GAME_CHAT_STRING,cad)
  293.  
  294. NetPlayer = "Player1"
  295.  
  296. def SetNetPlayerScorer(s):
  297.     global NetPlayer
  298.     NetPlayer = s
  299.  
  300. LastFragViewerTime = 0
  301.  
  302. def SwitchFragViewer():
  303.     global LastFragViewerTime
  304.     
  305.     LastFragViewerTime = Bladex.GetTime()+4.0
  306.     wPlayersFrags.SetVisible(1)
  307.     
  308. ViewStats = 0
  309.  
  310. def NetScorerAfterFrameFunc(time):
  311.     import Actions
  312.     global ScrollLimit
  313.     global NetPlayer
  314.     global LastFragViewerTime
  315.     
  316.     pj=Bladex.GetEntity(NetPlayer)
  317.     if "NetLife" in dir(pj.Data):
  318.         if "NetLevel" in dir(pj.Data):
  319.             info = netgame.GetPlayerData(NetPlayer)    
  320.  
  321.  
  322.             throw_pressed = Bladex.GetTimeActionHeld ("Throw")
  323.             if throw_pressed:
  324.                 SetStrengthBarValue(Actions.ThrowTime2ThrowForce(throw_pressed))
  325.                 wLowBarFrame.SetVisible(1)
  326.             else:                
  327.                 max_energy= CharStats.GetCharMaxEnergy(pj.Kind, 29)
  328.                 wStrengthBar.SetVisible(0)
  329.                 if info[0] < max_energy:
  330.                     SetEnergyBarValue(info[0]*1.0, max_energy*1.0)                    
  331.                     wLowBarFrame.SetVisible(1)
  332.                 else:
  333.                     wStrengthBar.SetVisible(0)
  334.                     wLowBarFrame.SetVisible(0)
  335.                     wEnergyBar.SetVisible(0)
  336.             
  337.             wLifeBar.SetPositionPercentage(info[1]/(pj.Data.NetLife/6.5*8.0))
  338.             wLifeLabel.SetText(str(info[1])+"/"+str(int(pj.Data.NetLife)))
  339.             wCurrentLevelLabel.SetText(MenuText.GetMenuText("Level")+" "+str(int(pj.Data.NetLevel)))
  340.             if ScrollLimit<time :
  341.                 ScrollChatConsole()
  342.             if LastFragViewerTime<time:
  343.                 wPlayersFrags.SetVisible(0)
  344.             if ViewStats:
  345.                 wStatusGame.SetText(netgame.ServerInfoBlock())
  346.     
  347. Bladex.SetAfterFrameFunc("DefaultSelectionData",NetScorerAfterFrameFunc)
  348.  
  349. def ActivateScorer():
  350.     Bladex.SetRootWidget(wFrame.GetPointer())
  351.  
  352.  
  353. wFrame.SetAutoScale(1)
  354.  
  355. if wants_auto_scale:
  356.     wLeftFrame.SetAutoScale(1)
  357.  
  358.     wDownFrame.SetAutoScale(1)
  359.     wChatFrame.SetAutoScale(1)
  360.     wFragFrame.SetAutoScale(1)
  361.  
  362.     wLifeMarker.SetAutoScale(1)
  363.  
  364.     wLifeLabel.SetAutoScale(1)
  365.     wLifeBar.SetAutoScale(1)
  366.     wLifeLabel.SetAutoScale(1)
  367.     wPoisonLabel.SetAutoScale(1)
  368.     wCurrentLevelLabel.SetAutoScale(1)
  369.     wPlayersFrags.SetAutoScale(1)
  370.     wPlayersVS.SetAutoScale(1)
  371.     wStatusGame.SetAutoScale(1)
  372.     wLowBarFrame.SetAutoScale(1)
  373.     wEnergyBmp.SetAutoScale(1)
  374.     wStrengthBar.SetAutoScale(1)
  375.     wMaxPowerLabel.SetAutoScale(1)
  376.     wStrengthLabel.SetAutoScale(1)
  377.     wEnergyBar.SetAutoScale(1)
  378.     wDangerLabel.SetAutoScale(1)
  379.     wEnergyMaxLabel.SetAutoScale(1)
  380.     wFragLimit.SetAutoScale(1)
  381.     wFragList.SetAutoScale(1)
  382.     for i in range(len(wChatLines)):
  383.         wChatLines[i].SetAutoScale(1)
  384.  
  385.